<script>
import { submitFeedBack } from "@/api/system/feedback";

export default {
  name: "index",
  data() {
    return {
      feedBackForm: {
        description: "",
        content: "",
        userId: this.$store.getters.uuid,
      },
      feedBackRules: {
        description: [
          { required: true, message: "请输入反馈标题", trigger: "blur" },
        ],
        create_time: [
          {
            type: "string",
            required: true,
            message: "请选择填写时间",
            trigger: "blur",
          },
        ],
        content: [
          { required: true, message: "请填写反馈内容", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 验证通过
          this.submitFeedBack();
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    //  发起提交反馈的请求
    submitFeedBack() {
      submitFeedBack(this.feedBackForm).then((res) => {
        if (res.code === 200) {
          this.$message.success("反馈成功");
          this.feedBackForm = {};
          this.$router.push("/feedback-manage");
        }
      });
    },
  },
  mounted() {},
};
</script>

<template>
  <div>
    <el-card style="height: 100vh">
      <!-- 表单内容 -->
      <el-form
        :model="feedBackForm"
        :rules="feedBackRules"
        ref="feedBackRef"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="反馈标题" prop="description">
          <el-input v-model="feedBackForm.description"></el-input>
        </el-form-item>
        <el-form-item label="反馈信息" prop="content">
          <el-input
            type="textarea"
            cols="30"
            rows="10"
            v-model="feedBackForm.content"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('feedBackRef')"
            >提交</el-button
          >
          <el-button @click="resetForm('feedBackRef')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<style scoped lang="scss"></style>
